<template>
  <div class="content">
    成功页面
    <div>{{ bid }}</div>
    <div>
      <img :src="qrcode" />
    </div>
  </div>
</template>
<script>
import { mapState } from "vuex";
import { getWechatByBid, qrcodeWithParams } from "@/assets/mp";
import { getSign } from "@/assets/utils";
export default {
  data() {
    return {
      qrcode: "",
    };
  },
  computed: {
    ...mapState(["pageInfo", "userInfo"]),
    bid() {
      return this.$route.params.bid;
    },
     qrcodeUrl() {
      return this.$route.params.qrCodeUrl;
    },
    bizType() {
      return this.pageInfo.bizType;
    },
  },
  methods: {
    // 获取投顾信息
    async getAdviserInfo() {
      const { code, mobilePhone, qrcodeUrl, qyCode, desc } =
        await getWechatByBid(this.bid);
      if (code !== "1") {
        errorTip(desc);
      }
      return { mobilePhone, qrcodeUrl, qyCode };
    },
    // 同步生成一客一码
    async getQrcodeWithParams() {
      const { qyCode, mobilePhone, qrcodeUrl } = await this.getAdviserInfo();
      console.log(qyCode, mobilePhone, qrcodeUrl);
      const params = {
        corpId: qyCode,
        bizMobile: mobilePhone,
        ruleCode: 102,
        channel: this.pageInfo.channel,
        sid: this.pageInfo.sid,
        bid: this.pageInfo.bid,
        reffer: this.pageInfo.reffer,
        openid: this.openid,
      };
      const headers = {
        "Content-Type": "application/json",
        serverId: 10011218,
        sign: getSign(params, this),
      };
      const { code, data } = await qrcodeWithParams(
        params,
        this.bizType,
        headers
      );
      if (code !== "1") {
        this.qrcode = qrcodeUrl;
      } else {
        this.qrcode = data;
      }
    },
  },
  async created() {
    console.log(this.pageInfo);
    console.log(this.userInfo);
    console.log(this.$route.params);
 if (this.qrcodeUrl) {
      this.qrcode = this.qrcodeUrl;
    } else {
      await this.getQrcodeWithParams();
    }
  },
};
</script>
<style lang="less" scoped>
.content {
  text-align: center;
  font-size: 60px;
  margin-top: 100px;
  img {
    width: 400px;
    height: 400px;
  }
}
</style>